var app = getApp(),
  a = app.requirejs("core");
var running = false;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: 0,
    jihuo:true,
    card_num:'xxxx xxxx xxxx',
    level_name:'',
    show: false,
    bomb: !0,
    shdz: !0,
    gz_show: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    "" == app.getCache("userinfo") && (a.toast('您还没登录呢'),
      setTimeout(function () {
        wx.redirectTo({
          url: "/yb_shop/pages/index/index"
        })
      }, 2e3));
    var that = this;
    a.setting();
    that.setData({
      userinfo: getApp().getCache("userinfo")
    });
    that.getinfo();
  },
  getinfo: function () {
    var that = this;
    a.get('Usercard/cardinfo', {
      uid: app.getCache('userinfo').uid
    }, function (t) {
      if (t.code == 0) {
        that.setData({
          level_name: t.info.level_name,
          info: t.info,
          show: true
        })
      } else {
        a.alert(t.msg);
      }
    }, !that.data.show);
  },
  lookck: function () {
    var s = this.data.gz_show;
    this.setData({
      gz_show: !s
    })
  },
  formSubmit: function (e) {
    var that = this;
    var data = e.detail.value;
    if (running) {
      return;
    }
    if (!data.name) {
      a.alert('请输入姓名！');
      return;
    }
    if (!data.mobile || data.mobile.length!=11) {
      a.alert('请输入11位的手机号');
      return;
    }
    data.uid=app.getCache('userinfo').uid;
    running = true;
    a.post('Usercard/addcard', data, function (t) {
      running = false;
      that.setData({jihuo:true});
      if (t.code == 0) {
        if(t.info==1){
          a.alert('提交成功,请耐心等待管理员激活！',function(){
            that.getinfo();
          });
        }else{
          a.success('激活成功');
          setTimeout(function(){
            that.getinfo();
          });
        }
      } else {
        a.alert(t.msg);
      }
    })
  },
  chongzhi:function(){
    a.jump('../recharge/index');
  },
  to_url:function(e){
      var i=a.pdata(e).i,url='';
      if(this.data.info.have!=1 && i!=3){
        a.warning('会员卡未激活');
        return;
      }else{
        if (i == 1) {
          url='../rechargelog/index?id='+this.data.info.user.id;
        } else if (i == 2) {
          url = '../consumeLog/index';
        } else if(i == 3){
          url = 'info';
        }else{
          return;
        }
        a.jump(url);
      }
  },
  open_jihuo: function () {
    this.setData({
      jihuo: false
    });
  },
  cancel_jihuo: function () {
    this.setData({
      jihuo: true
    });
  },


  /**
* 下拉刷新
*/
  onPullDownRefresh: function () {
    this.getinfo();
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
 /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})